package UILayer;
import CtrLayer.*;

/**
 * Submenu "dvd's".
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class DvdUI
{
    // instance variables
    private DvdCtr dvdCtr;
    private Parser parser;

    public DvdUI(DvdCtr dvdCtr)
    {
        // initialise instance variables
        this.parser = new Parser();
        this.dvdCtr = dvdCtr;
    }

    /*
     * Menu for dvd
     */
    public void dvdMenu()
    {
        boolean exit = false;
        writeMenu();
        while(!exit)
        {
            int choice = parser.scanChoiceInput();
            if(choice == 1) { //Create dvd
                createDvd();
                writeMenu();
            }
            if(choice == 2) { //add copy of dvd
                createDvdCopy();
                writeMenu();
            }
            if(choice == 3) { //find dvd
                findDvd();
                writeMenu();
            }
            if(choice == 4) { //delete dvd and copies of it
                deleteDvd();
                writeMenu();
            }
            if(choice == 5) { //delete a copy of a dvd
                deleteDvdCopy();
                writeMenu();
            }
            if(choice == 6) { //go back
                exit = true;
            }
        }
    }

    public void writeMenu()
    {
        System.out.println("********* DVD menu *********");
        System.out.println("*  (1) add dvd             *");
        System.out.println("*  (2) add  copy of dvd    *");        
        System.out.println("*  (3) find dvd            *");
        System.out.println("*  (4) delete dvd          *");   
        System.out.println("*  (5) delete copy of dvd  *");        
        System.out.println("*  (6) back                *");
        System.out.println("****************************");
    }

    public void createDvd()
    {
        System.out.println("Enter barcode: ");
        String barcode = parser.scanInputString();

        System.out.println("title: ");
        String title = parser.scanInputString();

        System.out.println("artist: ");
        String artist = parser.scanInputString();

        System.out.println("publicationDate: ");
        String publicationDate = parser.scanInputString();

        dvdCtr.createDvd(barcode, title, artist, publicationDate);
    }

    public void createDvdCopy()
    {
        System.out.println("Enter title of dvd you wish to add copy of: ");
        String title = parser.scanInputString();      

        System.out.println("Enter the serial numberof the copy: ");
        String serialNumber = parser.scanInputString();  

        System.out.println("Date of purchase: ");
        String purchaseDate = parser.scanInputString();  

        System.out.println("Purchase price: ");
        String purchasePrice = parser.scanInputString();

        if(dvdCtr.createCopy(serialNumber, purchaseDate, purchasePrice, title)) {
            System.out.println("Copy created");
        }
        else {
            System.out.println("Couldn't create copy");
        }
    }

    public void findDvd()
    {
        System.out.println("Enter title of dvd you want to find: ");
        String title = parser.scanInputString();

        dvdCtr.findDvd(title); 
        if(dvdCtr.findDvd(title) != null) {
            dvdCtr.findDvd(title).printInfo();
        }
        else {
            System.out.println("No dvd with title of: " + title);
        }
    }

    public void deleteDvd()
    {
        System.out.println("Enter title of dvd you want to delete: ");   
        dvdCtr.deleteDvd(dvdCtr.findDvd(parser.scanInputString()));
    }

    public void deleteDvdCopy()
    {
        System.out.println("Enter serial number of the copy you want to delete: ");
        dvdCtr.deleteCopy(parser.scanInputString());
    }
}
